package com.springboot.study;

import com.springboot.study.interceptor.LogInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * web 拦截器/参数解析器/消息转换的配置
 *
 * <br>
 * <mvc:interceptors> <mvc:argument-resolvers> <mvc:message-converters>
 *
 */
// 增加@EnableWebMvc注解，关闭spring boot的mvc默认配置，改为自定义配置
@EnableWebMvc
@Configuration
public class CustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {


		// 注入http请求响应的拦截，记录日志
		registry.addInterceptor(new LogInterceptor());


	}


	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		// 配置资源映射
		// <resources mapping="/js/**" location="/js/" />
		// 其中默认配置的 /** 映射到 /static （或/public、/resources、/META-INF/resources）
		// 其中默认配置的 /webjars/** 映射到 classpath:/META-INF/resources/webjars/

		// registry.addResourceHandler("/upload/**").addResourceLocations("classpath:/upload/");
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
		// super.addResourceHandlers(registry);
	}





}
